<table width="100%"  border="0" cellPadding=0 cellSpacing=0>
 <tr><td colspan="3" bgcolor="#333333" ></td></tr>
  <tr>
    <td width="75%" style="padding-left:10px;padding-top:10px " valign="top"><?
if (eregi("memSellLeads.php",$_SERVER['PHP_SELF'])) {	
	die("&nbsp;");
}
//check_gpc();
 
$template_leads_body="template/memSellLeads.tpl";
$template_detail="template/memSellLeadsdetail.tpl";
$base_url 	= 'index.php';
 $mode=isset($_GET["mode"]) ? htmlspecialchars($_GET["mode"]) :'';
switch($mode){ 
  case "leadsdetail":
 	  LeadsDetail();
	  break;
  default:
	  viewProduct(); 
	  break; 
}

function LeadsDetail(){
	global $template, $db, $template_detail,$cid,$site_base_href,$base_url;
	
	 $lid=isset($_GET["lid"]) ? intval($_GET["lid"]) :'';

	//echo "hello";
	$sql="select * from vb_sell_lead where lID=".$lid;
	if(!$result=$db->sql_query($sql)){
	  message_die("Couldn't run the sql query!!!","",__LINE__,__FILE__,$sql);
	}	 
	$lead_data=$db->sql_fetchrow($result);	
	$sql="select  m.memID, m.FirstName, m.LastName, m.CompanyName, m.Sex, 
	m.AlternativeEmail,m. BusinessType, m.IndustryCategory, m.NumberEmployees, m.Address, m.City, 
	m.State, m.Zip, m.Web, m.JobTitle, m.contrycode, m.areacode, m.BusinessPhone, m.faxcontrycode, 
	m.faxareacode, m.FaxNumber, m.Mobile, m.fName, m.countryID, m.orthJob, m.lName, 
	 m.CompanyName_vn, m.Address_vn, m.fName_vn,  m.lName_vn, m.FirstName_vn, m.LastName_vn, m.City_vn,
	 m.State_vn, m.orthJob_vn, m.lastEdit,  m.lastEdit_vn, m.id,c.* from vb_companyprofile c inner join vb_memberprofile m on c.memID=m.memID where c.memID=".$cid;
		if(!$result=$db->sql_query($sql)){
		  message_die("Couldn't run the sql query!!!","",__LINE__,__FILE__,$sql);
		}	
		$mem_data=$db->sql_fetchrow($result);		
		$proInfo=getproInfo($lead_data["proID"]);		
		
				$simages='<img src="products/'.$proInfo["images180"].'" border="0" class="imageborder">';
				if(!ereg(".jpg",$proInfo["images180"]) && !ereg(".gif",$proInfo["images180"]) ){				 	
					$simages='<img src="images/no_photo.gif" class="imageborder">';
				}
		
		$memName= $mem_data["fName"] ."&nbsp;". $mem_data["lName"];
		$template->assign_vars(array(
			'companyName'	=>  $mem_data["CompanyName"],		
			'maintitle'		=>$mem_data["CompanyName"] . ' - yellowpages.vn | Vietnam - ',  
			'com_photo'	=> !empty($mem_data["barner"]) ? "<img src=\"barner/".$mem_data["barner"]."\">" : '' , 
			'leadName' => $lead_data["subject"],
			'supp'	=>$cid,
			'postdate' 	=> date("Y-m-d",$lead_data["datepost"]),
			'proid'		=>$lead_data["proID"],
			'lid'		=>$lid,
			'Expirydate' => getExpried($lead_data["Effective"],$lead_data["datepost"]),
			'mURL'		=>'supplier.php?supplier='.$cid.'&act=products&mode=productDetail&pid='.$lead_data["proID"]."&catID=".$lead_data["catID"],			 
			'photo'		=>'<a href="javascript:void(0)" class="lMenu" onClick="openwin(\'largerImage.php?img='.$proInfo["Images"].'&imgn='. urlencode($proInfo["ProductName"]).'\',120,120)">'.$simages.'</a>',			
			'proName'	=>$proInfo["ProductName"],
			'ProModel'	=> !empty($lead_data["Model"]) ? 'Model Number :  '.$lead_data["Model"].'<br>' : '',
			'quantity'	=>!empty($lead_data["quantity"]) ? 'Quantity :  '.$lead_data["quantity"].'<br>' : '', 			
			'detail'	=>html_entity_decode(nl2br($lead_data["details"])),			
			'company'	=> $mem_data["CompanyName"],
			'ContactName'	=>($mem_data["Sex"]=="Male" ? "Mr. " : "Ms. ") . $memName,
			'Address'	=>$mem_data["Address"],
			'city'		=>$mem_data["City"].", ".getContry($mem_data["countryID"]),
			'zipCode'	=>$mem_data["Zip"],
			'Telephone'	=>  $mem_data["contrycode"] ."-".$mem_data["areacode"]."-".$mem_data["BusinessPhone"],
			'mobiphone'	=>$mem_data["Mobile"],
			'fax'	=>$mem_data["faxcontrycode"] ."-".$mem_data["faxareacode"]."-".$mem_data["FaxNumber"],
			'Website'	=>$mem_data["Web"],
			'a_action' =>"supplier.php?supplier=".$cid."&act=memcontacts&mode=main",
			'NAVIGATOR'     => $pagination,
			'divtel'	=> !empty($mem_data["BusinessPhone"]) ? 'bock' : 'none',
			'divmobi'	=> !empty($mem_data["Mobile"]) ? 'bock' : 'none',
			'divfax' => !empty($mem_data["FaxNumber"]) ? 'bock' : 'none',
			'divweb' => !empty($mem_data["Web"]) ? 'bock' : 'none',
			'divcontactName' =>strlen($memName)>9 ? 'bock' : 'none',
		));
 
	$template->set_filenames(array(
		"body"	=> $template_detail
	));
	$template->pparse('body');
} 
function viewProduct(){
	global $template, $db, $template_leads_body,$cid,$site_base_href,$base_url,$catID,$sqlCommon,$langUrl;
	$start		= isset($_GET["start"]) ? intval($_GET["start"]) : 0;
	 
	$display=15;
	$txtgoto=isset($_POST['txtgoto']) ? intval($_POST['txtgoto']) : 0; 
	
	 if($txtgoto){
		//$start	=  floor($txtgoto*$display)-1; 		
		$start	=  floor(($txtgoto-1)*$display); 		
	}
	
	$proName=array();	
	$images=array();	
	$proModel=array();	
	
	$sql="select proID,sImages,Model,ProductName,catID from vb_products where memID=".$cid;
	if(!$result=$db->sql_query($sql)){
	  message_die("Couldn't run the sql query!!!","",__LINE__,__FILE__,$sql);
	}
	$pro_count=$db->sql_numrows($result);
	$pro_data=$db->sql_fetchrowset($result);	
	for($i=0;$i<$pro_count;$i++){
		$proName[$pro_data[$i]["proID"]]=$pro_data[$i]["ProductName"];
		$images[$pro_data[$i]["proID"]]=$pro_data[$i]["sImages"];
		$proModel[$pro_data[$i]["proID"]]=$pro_data[$i]["Model"];
		$proID[$pro_data[$i]["proID"]]=$pro_data[$i]["catID"];
	}		
	unset($pro_data);
	$sql="select * from vb_sell_lead where $sqlCommon) and active=1 and memID=".$cid." limit $start,$display" ;
	if(!$result=$db->sql_query($sql)){
	  message_die("Couldn't run the sql query!!!","",__LINE__,__FILE__,$sql);
	}
	$pro_count=$db->sql_numrows($result);
	$pro_data=$db->sql_fetchrowset($result);	
	
	$sql = 'SELECT count(proID) AS total FROM vb_sell_lead where '.$sqlCommon.') and active=1 and memID='.$cid;
	if ( !$result = $db->sql_query($sql) ) {
		message_die("Couldn't run the sql query!!!", __LINE__, __FILE__, $sql);
	}
	 $total= $db->sql_fetchrow($result);
	 
	if($total['total']<1){
	  echo '<br>There are no product<br><br>';
		return;
	}
	$pagination 	= g3_pagination("supplier.php?supplier=".$cid."&act=vleads", $total['total'], $display, $start, 'start', 'Page ' . '//<img src="images/prev.gif" border="0">//<img src="images/next.gif" border="0">')."&nbsp;";
	$total_pages = ceil($total['total']/$display);
	$db->sql_freeresult($result);
	
		for ($i=0; $i<$pro_count; $i++){
				
				$simages='<img src="products/'.$images[$pro_data[$i]["proID"]].'" border="0" class="imageborder">';
				if(!ereg(".jpg",$images[$pro_data[$i]["proID"]]) && !ereg(".gif",$images[$pro_data[$i]["proID"]]) ){				 	
					$simages='<img src="images/no_photo.gif" class="imageborder">';
				}
			 
			$template->assign_block_vars("productList", array(							
				'Subject'	 => '<a href="supplier.php?supplier='.$pro_data[$i]["memID"].'&act=vleads&mode=leadsdetail&lid='.$pro_data[$i]["lID"].'&catID='.$proID[$pro_data[$i]["proID"]].'" class="proLink">'.$pro_data[$i]["subject"].'</a>',
				'pName'		 => 'Product Name :&nbsp; '.	$proName[$pro_data[$i]["proID"]],
			 	'pModel'	 =>'Model No : '.	$proModel[$pro_data[$i]["proID"]],		
				'detail'		 =>	substr(html_entity_decode(nl2br($pro_data[$i]["details"])),0,150)." ...",		
				'photo'		 => '<a href="supplier.php?supplier='.$pro_data[$i]["memID"].'&act=vleads&mode=leadsdetail&lid='.$pro_data[$i]["lID"].'&catID='.$proID[$pro_data[$i]["proID"]].'" class="lMenu">'.$simages.'</a>' ,
				'CHECKBOX'	 => '<input type="Checkbox" name="proid['.$pro_data[$i]["lID"].']" value="'. $pro_data[$i]["proID"] .'" />',
			));
	  }
	$sql="select  m.memID, m.FirstName, m.LastName, m.CompanyName, m.Sex, 
	m.AlternativeEmail,m. BusinessType, m.IndustryCategory, m.NumberEmployees, m.Address, m.City, 
	m.State, m.Zip, m.Web, m.JobTitle, m.contrycode, m.areacode, m.BusinessPhone, m.faxcontrycode, 
	m.faxareacode, m.FaxNumber, m.Mobile, m.fName, m.countryID, m.orthJob, m.lName, 
	 m.CompanyName_vn, m.Address_vn, m.fName_vn,  m.lName_vn, m.FirstName_vn, m.LastName_vn, m.City_vn,
	 m.State_vn, m.orthJob_vn, m.lastEdit,  m.lastEdit_vn, m.id,c.* from vb_companyprofile c inner join vb_memberprofile m on c.memID=m.memID where c.memID=".$cid;
		if(!$result=$db->sql_query($sql)){
		  message_die("Couldn't run the sql query!!!","",__LINE__,__FILE__,$sql);
		}	
		
		$mem_data=$db->sql_fetchrow($result);		
		
		$memName= $mem_data["fName"] ."&nbsp;". $mem_data["lName"];
		
		$template->assign_vars(array(
			'company'	=> $mem_data["CompanyName"],
			'maintitle'		=>$mem_data["CompanyName"].' - yellowpages.vn | Vietnam - ', 
			'supp'	=>$cid,
			'companyName'	=>  $mem_data["CompanyName"],		 
			'com_photo'	=> !empty($mem_data["barner"]) ? "<img src=\"barner/".$mem_data["barner"]."\">" : '' ,
			'ContactName'	=> ($mem_data["Sex"]=="Male" ? "Mr. " : "Ms. ") .$memName,
			'Address'	=>$mem_data["Address"],
			'city'		=>$mem_data["City"].", ".getContry($mem_data["countryID"]),
			'zipCode'	=>$mem_data["Zip"],
			'Telephone'	=>  $mem_data["contrycode"] ."-".$mem_data["areacode"]."-".$mem_data["BusinessPhone"],
			'mobiphone'	=>$mem_data["Mobile"],
			'fax'	=>$mem_data["faxcontrycode"] ."-".$mem_data["faxareacode"]."-".$mem_data["FaxNumber"],
			'Website'	=>$mem_data["Web"],
			'a_action' =>"supplier.php?supplier=".$cid."&act=memcontacts&mode=main",
			'NAVIGATOR'     => $pagination,
			'navidis'  => $total_pages>1? 'display' : 'none',
			'g_action' =>"supplier.php?supplier=".$cid."&act=vleads",
			'divtel'	=> !empty($mem_data["BusinessPhone"]) ? 'bock' : 'none',
			'divmobi'	=> !empty($mem_data["Mobile"]) ? 'bock' : 'none',
			'divfax' => !empty($mem_data["FaxNumber"]) ? 'bock' : 'none',
			'divweb' => !empty($mem_data["Web"]) ? 'bock' : 'none',
			'divcontactName' =>strlen($memName)>9 ? 'bock' : 'none',
			'oldurl' =>$langUrl
		));
 
	$template->set_filenames(array(
		"body"	=> $template_leads_body
	));
	$template->pparse('body');
	$template->destroy();
	$proName=array();	
	$images=array();	
	$proModel=array();	
	$pro_data=array();
}

 function getproInfo($id=0){
	global $db;
	$sql="select images180,Images,Model,ProductName from vb_products where proID=".$id;
	if(!$result=$db->sql_query($sql)){
		message_die("Couldn't run the sql query!!!","",__LINE__,__FILE__,$sql);
	 }
	  
	return $db->sql_fetchrow($result);
}

?></td>
<td  bgcolor="#333333"></td>
    <td width="25%" valign="top" style="padding-top:10px " ><table width="200" border="0">
      <tr>
        <td style="padding-left:10px "><strong>Categories</strong></td>
      </tr>
      <tr>
        <td style="padding-left:10px ">

		<? include "uproducts.php"?></td>
      </tr>
    </table></td>
  </tr>
</table>

		
		